Repository navigation
qwen3_5 cuda: accept mcg codebook alongside mul1 - #3412
Conversation
Stage 6b's Gate 4 was blocked on upstream TensorFold's Qwen3.5 CUDA loader hard-coding the EXL3 mul1 codebook. Stage 6c: 1. Opens ashhart#3412 teaching the loader to accept mcg codebooks alongside mul1 (3-line policy patch + 2 tests). 2. Adds f16-embed/f32-norm/f32-A_log widening helpers for ExLlamaV3's checkpoint conventions (follow-up commit on the same PR). 3. Captures Gate A evidence: real tokens from the turboderp/Qwen3.5-2B- exl3-8.00bpw safetensors through the patched tf-qwen35-cuda binary on the GB10 DGX Spark. Final-logits sha256 6b198ea823135943d8d662837ca0c42e7ab4165addfa2064a23eb0be3824c1e0; deterministic across runs; 16-token greedy continuation produces ' 42.\nA. True\nB. False\n\n<think>\nThinking'. 4. Proves Gate B: the 3.2 GiB TFOLD v0.2 checkpoint materialized back to safetensors via tools/tfold_convert/tfold_to_safetensors.py produces BYTE-IDENTICAL logits through the same binary. Same SHA, same argmax, same token continuation. Deliverables: - docs/stage6c-gate-a-receipt.json: Gate A inference evidence - docs/stage6c-gate-b-receipt.json: Gate B TFOLD round-trip evidence - docs/stage6c-v02-tfoldfile-design.md: TfoldFile adapter design for a native v0.2 reader seam (follow-up Stage 6d scope) - docs/tfold-stage6c-conformance.md: full milestone conformance - learning-notes/stage06c-mcg-loader-tokens.md: beginner-friendly companion covering the patch, alternatives considered, hands-on reproduction - tools/tfold_convert/tfold_to_safetensors.py: TFOLD v0.2 -> safetensors materializer (byte-identical tensor regions; no re-quantization) - tools/tfold_stage6c/decode_tokens.py: output-file token decoder - tools/tfold_stage6c/capture_gate_a.sh: deterministic capture harness Upstream PR: ashhart#3412 (fork branch stage6c-cuda-mcg @ ee6a7f1). Tests: 105/105 Stage 6b tests still pass on this fork, zero regressions. Upstream tests on the PR: test-qwen35-exl3-admission-host 5/5 pass (2 new mcg tests), test-exl3-cuda-host 671/681 pass + 10 skip (unchanged).
auditbenchaibot
left a comment
There was a problem hiding this comment.
🤖 Automated review by Audit Bench Ai, not a personal review. It was posted through the GitHub account connected to Audit Bench Ai. Install the Audit Bench Ai GitHub App to have reviews posted by a separate bot account.
No actionable comments were generated in this review. 🎉
Merge readiness: 🟡 Ready to merge, with notes
Pre-merge checks: ✅ 4 · ⚠️ 1
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| CI checks | No CI checks ran on this commit. | Add CI so every PR is built and tested. |
✅ Passed checks: 4 passed
| Check name | Status | Explanation |
|---|---|---|
| Merge conflicts | ✅ | Merges cleanly into main. |
| Secrets | ✅ | No keys, passwords or tokens in the changed code. |
| Blocking issues | ✅ | No critical or high-severity issues in the changed lines. |
| PR size | ✅ | 133 lines changed. |
ℹ️ Review info
- Commit:
1fb837d - Verdict: ✅ Pass
- Findings: none
- Review: local checks plus AI review of the changed lines
- Scope: Reviewed 0/0 selected files (of 0 total): 0 reviewed by AI, 0 from cache, 0 passed local checks with nothing risky enough to send to AI. Found 0 finding(s), No secrets found.
💬 Reply to any inline comment and Audit Bench Ai will recheck that code and answer in the thread. Mention @auditbench in the conversation to ask about the whole PR.
🛠️ Open the full report and fix with AI
Thanks for using Audit Bench Ai! Free pull request reviews for open source: paste any public PR at auditbenchai.com/scan.
Reviewed by Audit Bench Ai · Build fast. Check what ships. · Review any public PR free
Stage 6c ended with the materializer bridging .tfold -> safetensors on disk. Stage 6d removes that bridge: a native v0.2 reader lives in upstream TensorFold (branch stage6d-tfold-reader @ 67867bf), and the CUDA runtime now loads model.tfold directly through Checkpoint. Deliverables (this commit on stage6b-cuda, our fork's tfold-dev branch): - docs/tfold-stage6d-conformance.md: Gate C PASS report with per-path cold/warm walltime, peak RSS, and SHA comparison. - docs/stage6d-gate-c-receipt.json: machine receipt of three-way measurement (native/safetensors/materialized, cold + warm). - learning-notes/stage06d-native-tfold.md: beginner-friendly companion covering mmap zero-copy semantics, the host->GPU hop that is NOT zero-copy, memory ownership/alignment/verification/cleanup, design alternatives, and two unanswered comprehension questions. - tools/tfold_stage6d/measure_gate_c.sh: capture harness. Upstream deliverables (on stage6d-tfold-reader @ 67867bf): - zig/src/core/tfold_file.zig (new, ~280 LoC) - zig/src/core/tfold_file_test.zig (new, 13 tests) - zig/src/core/checkpoint.zig (openModelPrefixes detects model.tfold) - zig/src/core/root.zig / zig/build/checkpoint_io_host.zig: test wiring Gate C on GB10 Spark against turboderp/Qwen3.5-2B-exl3-8.00bpw: native_warm: 5.523 s, 7.3 GB RSS, sha=6b198ea8...3824c1e0 safetensors_warm: 4.210 s, 6.1 GB RSS, sha=6b198ea8...3824c1e0 materialized_warm: 3.863 s, 6.1 GB RSS, sha=6b198ea8...3824c1e0 three_way_sha_match: true Native is ~1.3 s slower than materialized because FNV-1a-64 trailer verification runs by default. We did NOT weaken that policy to report a speedup; the brief explicitly forbids it. Test totals: 105/105 preserved on our fork (0 regressions). Upstream tests: 59/59 checkpoint-io (12 new tfold_file tests), 5/5 qwen35-exl3-admission, 1017/1027 exl3-cuda-host (10 skip unchanged). The mcg PR (ashhart#3412) stays separately reviewable at Ch0mpaa/TensorFold:stage6c-cuda-mcg; Stage 6d is layered as its own branch Ch0mpaa/TensorFold:stage6d-tfold-reader.
|
Thanks @Ch0mpaa. The mcg admission tests pass, but the second commit needs changes before this can land.
|
|
Thanks for the detailed review, @ashhart. All three findings are fair; the draft plan below maps directly to them. (1) Mapped vs. device F16→BF16 at (2) FP32 → BF16 narrowing + patch scope. Correct, that's a narrowing, not widening — and it has no business riding on the MCG admission patch. I'll split the series:
That way reviewers can land (A) immediately and evaluate (B) on its numerical merits. (3) Lean findings, fmt, CI, PR body. Will run I appreciate the precision — especially catching the F16/BF16 mapped-vs-device value mismatch; marker-only admission tests couldn't have surfaced it. |
|
Thanks @Ch0mpaa for the quick, careful reply, and for agreeing to split the series. That plan sounds right to us. The head is still The mcg part looks good. Existing mul1 checkpoints follow the same path with the same bytes: the
Optional:
Once the split is pushed, could you post main-against-branch token outputs for one existing mul1 Qwen3.5 EXL3 checkpoint, and branch outputs for the mcg 2B checkpoint, at the new head? Thanks again for chasing this down.
|
1fb837d to
ee6a7f1
Compare
|
@ashhart / Synthena — fixes landed, responding to each finding. Summary of the splitI split the series as planned:
Finding 1 — mapped vs device F16→BF16 mismatch at
|
Beginner-friendly explanation of the F16/BF16 mapped-vs-device embedding corruption that Synthena caught in PR ashhart#3412 review, the F32-to-BF16 norm narrowing finding, how we split the series, and the tests that now catch both regressions. Covers: - F16 vs BF16 bit layout (why F16 1.0 = 0x3C00 reads as BF16 0.0078125) - Why embedTokens() device path converted but mappedEmbed() mapped path did not - The fix: mappedEmbed() now routes through f16Rows() mirroring embedTokens() exactly; broken embedTensor() helper deleted - F32 norm narrowing is kernel-correct (tf_q35_gdn_post reads __nv_bfloat16) but the comment said 'widening' which was wrong; docs fixed + numerical regression test bounds the narrowing error to <= 2^-7 * |x| - Mapped vs device memory tradeoffs on discrete GPUs - What changed, why, alternatives considered - One hands-on exercise reproducing the 128x rescaling bug in under a minute - Two open comprehension questions Repo state after this close-out: stage6c-cuda-mcg at ee6a7f1 (admission only; PR ashhart#3412 head) stage6c-cuda-dtype at 53f119b (dtype + F16 fix + lean + fmt; pending its own PR after ashhart#3412 lands) CI on PR ashhart#3412: action_required (fork-PR maintainer approval gate, not a failure). Will NOT re-request review until CI confirms green per brief.
ee6a7f1 to
5d6dc70
Compare
|
Thanks @ashhart / Synthena — your three open items and the plan correction landed. Updated status against the new branch heads. 1. Mapped F16 embeddings (now at new PR head)Fixed on Three tests in
Audit result on Full-tensor scan, chunked in Python+numpy. The checkpoint was authored in bf16 and stored as f16 for compat; every stored word has mantissa_low_3 == 0, so 2. Narrowing in commit B (your correction is right; pivoted)You're right that tolerance is not enough. I audited the real F32 norm values before touching code: So narrowing drops information on 85% of these values. Can't ship that. Pivot: dropped F32 norm support from commit B entirely. Commit B at
Supporting F32 norms needs a kernel-side F32 norm path in 3. fmt, lean, body, CI
Optional items
Summary of new heads
Please approve the CI run on |
5d6dc70 to
ff439ed
Compare
Ran test-qwen35-exl3-admission-host + test-exl3-cuda-host + related host suites on DGX Spark (NVIDIA GB10, sm_121, CUDA 13) against both the mcg admission branch (ff439ed) and the follow-up dtype branch (e9558e2). RESULTS: * 712 tests pass on both branches (6 admission + 671 exl3-cuda + 23 cache + 1 exl3-owner + 11 formats); 10 skip; 0 fail * End-to-end tf-qwen35-cuda on Qwen3.5-2B-exl3-8.00bpw correctly refuses with UnexpectedTensor at the f32 linear_attn.norm.weight (both branches, as designed per Synthena's exactness requirement) REGRESSION CAUGHT AND FIXED: Stage 7E hygiene commit (5d6dc70) introduced a buffer-aliasing bug in admit.group(): mul1_name and mcg_name shared one &buf stack buffer, so the second bufPrint overwrote the first. A mul1-only checkpoint was then refused because ck.has(mul1_name) read bytes spelling 'p.mcg' not 'p.mul1'. Three admission tests failed on Spark that hadn't been caught in the Windows standalone harness. Fix in ff439ed (amended PR head): second mcg_buf for mcg_name. After fix: 6/6 admission tests pass. SCOPE GUARDS HONORED (per operator brief): * Did NOT expand PR ashhart#3412 beyond the admission + buffer-alias fix * Did NOT re-introduce f32->bf16 norm narrowing on either branch * F32 norms report as unsupported (correctly refused) * Did NOT request upstream re-review (CI not green on fork PRs without maintainer approval) * stage6c-cuda-dtype branch kept separate at e9558e2 DELIVERABLES: * docs/stage7f-pr3412-local-regression.json - machine-readable receipt with exact commands, SHAs, counters, error messages, inventory of HF Qwen3.5 EXL3 checkpoints (all mcg; no mul1 Qwen3.5 variant exists for inference regression) * learning-notes/upstream-pr3412-dtype-correctness.md - journal appendix (section 12) explaining the buffer-alias bug, the fix, and what Spark regression does + does not prove Local Spark host tests: 712 pass across both branches. Upstream CI at ff439ed: action_required (fork-PR maintainer approval gate; no verdict yet). Returning focus to the Qwen3.5-2B Chop Shop Dyno per operator direction.
Final local CUDA validation for the mcg admission commit at upstream PR ashhart#3412 head ff439ed, ran in a Spark worktree detached at that SHA. HOST TEST SUITES (all Zig, Spark, zig 0.17.0 + CUDA 13): * test-qwen35-exl3-admission-host: 6 pass, 0 fail * test-exl3-cuda-host: 1000 pass, 10 skip, 0 fail * test-qwen35-cache-host: 23 pass, 0 fail * test-qwen35-exl3-owner-host: 1 pass, 0 fail * test-qwen35-formats-host: 11 pass, 0 fail * test-exl3-prompt-host: 7 pass, 0 fail * test-glm-exl3-prompt-host: 5 pass, 0 fail * test-glm-formats-host: 12 pass, 0 fail TOTAL: 1065 pass, 10 skip, 0 fail FMT + LEAN: both clean on modified files. CHECKPOINT: Qwen3.5-2B-exl3-8.00bpw (mcg, F16 embed, F32 norms, F32 A_log). sha256=a106b1c9d58a768eb87960daa7aff6efd250b0cb7c73edb92155ac9fc653f45f REAL-CHECKPOINT LOAD on admission branch alone: error: embed_tokens.weight: f16 { 248320, 2048 }, expected bf16 error: UnexpectedTensor This is the correct refusal. The admission branch does not widen F16 embeddings; that's the dtype branch (e9558e2). With the dtype branch, load would refuse later at F32 linear_attn.norm.weight (Stage 7F). MUL1 Qwen3.5-2B: not available. Exhaustive HF search confirms no mul1 Qwen3.5 variant exists. MUL1 admission is exercised via synthetic host tests only. We do NOT compare mul1 vs mcg outputs (different codebooks; outputs must each be compared against their own reference). NEGATIVE: dual-marker refusal passes (error.UnsupportedQwenQuantization). The Stage 7E buffer-alias bug that broke two pre-existing mul1 tests plus the new dual-marker test is fixed in ff439ed (second mcg_buf). UPSTREAM CI: action_required at ff439ed. Workflows have not executed. Local Spark validation and upstream CI are reported independently. SCOPE GUARDS: PR ashhart#3412 scope unchanged; no merge; dtype on separate branch; no F32 norm narrowing reintroduced; no re-request of review. DELIVERABLE: docs/pr3412-cuda-regression.md (full command transcript, counters, SHAs, failure modes, scope guards).
CORRECTIONS TO v0 BASELINE:
Operator pushed back on the Stage 7G finding (0/10 CWE greedy,
0.42/10 sampled) before attributing it to model capability. Audit
caught four harness bugs:
1. Chat template never applied. Qwen3.5-2B IS an instruct model
(chat_template.jinja 7755 chars, eos <|im_end|>). v0 passed raw
text as a continuation prompt. Fix: hf_chat_template with
add_generation_prompt=True.
2. max_new_tokens=16 truncated 10-item structured output. Fix: 640.
3. Highest-risk criterion from scenario spec was never implemented.
Fix: v1.1 prompts for HIGHEST-RISK: CWE-NNN, scored separately.
4. 50 greedy trials with varied seeds = 1 sample pasted 50 times.
Greedy ignores seed. Fix: report T=0 column as determinism floor
only; use varied prompt formulations (batched vs single-snippet)
for reliability measurement.
v1 HONEST RESULT (same model, same checkpoint):
* T=0 greedy ChatML batched: 2.0/10 per trial (vs v0's 0/10)
* T=0 greedy ChatML single: 2.0/10 per trial, DIFFERENT 2 slots
* highest-risk CWE-78: 0/50 (predicted CWE-22 mode-collapse)
* per-slot audit: slots 1+3 always correct batched; 1+9 always
correct single; model knows SQLi (CWE-89) and path (CWE-22) but
enters repetition loop thereafter (batched) or has limited
coverage of the other categories (single-snippet).
TFOLD INFERENCE RECOVERED:
Stage 7G claim 'tf-qwen35-cuda returns NoSafetensors on .tfold' was
caused by testing on stage6c-cuda-mcg which predates the TFOLD
reader. The reader + CLI auto-detect ship on stage6d-tfold-reader
(67867bf) and stage6e-tfold-perf (015624e). Switched to a
worktree at the latter.
FAIR EXL3 vs TFOLD BENCHMARK:
Same tf-qwen35-cuda binary, same 8-token prompt, same output path.
EXL3 safetensors: cold 109.8, warm mean 108.1 tok/s
TFOLD v0.2: cold 109.0, warm mean 107.5 tok/s
Output MD5: c6a03e566512fa102ab5b5d25eb64782 (IDENTICAL on
both formats - proves kernels, tokens, logit bytes
are byte-identical)
Decoder throughput is statistically indistinguishable because both
formats route through the SAME CUDA kernels; only the loader differs.
Any TFOLD perf wins have to show in COLD LOAD, not decode.
DELIVERABLES:
* docs/2b-dyno-baseline.json - v1 with ChatML bugfix + fair
benchmark + scenario v1.1 rubric
* docs/dyno/offsec/v1_t0_direct.json - 50 trials T=0 batched raw
* docs/dyno/offsec/v1_single.json - 20 trials T=0 single-snippet
* docs/dyno/native/bench_native_results.txt - fair EXL3 vs TFOLD
* learning-notes/2b-dyno-foundation.md §11 - v1 addendum with
the mode-collapse finding + a
third comprehension question
SCOPE GUARDS HONORED:
* No SFT/DPO/QLoRA started. The evidence does not yet justify
training; it justifies prompt engineering first.
* PR ashhart#3412 untouched (dtype branch untouched).
* No new quantization.
* No larger models.
* Mode collapse NOT claimed as proof of model weakness; batched vs
single-snippet mismatch proves it's a decoder failure mode.
* T=0.7 x 50 trials run exceeded session budget and was killed;
reported honestly. v2 should complete it.
OFFSET DYNO v1.1 SCENARIO SCORECARD:
Graduated: NO. The scenario is now INSTRUMENTED (chat template,
highest-risk, rubric unit tests, per-slot audit, fair variance
across prompt formulations) but not yet GRADUATED (needs T=0.7
sweep, independent second scorer implementation, prompt
engineering trials to see if mode collapse is addressable without
training).
DO NOT declare 2B class graduated.
|
@Ch0mpaa, we applied the series to main and ran the admission suite here: it is green, and the change does what the Two things stand between this and a landing, and neither is code. First, CI: we approved the workflow runs at Also, please confirm the head you want reviewed: your last comment names a newer head than the series we were
|
|
Thanks @Ch0mpaa. We re-read the head
Two small things, then a device check.
The device check is still open from 16 Nov:
If you still can't reach a CUDA GPU, please say so here.
|
|
Thanks @Ch0mpaa. The split and marker refusals are in place, and the three-way check is clean. Please confirm
|
|
I checked the exact The extra case fed 128×128 synthetic safetensors into the measurement sink in Igor Lessio - AIFLOW LABS |
|
Thanks @Ch0mpaa. The code is still what the split promised, and the independent host check posted here exercises the dense and expert codebooks too. Three things from our last two comments are still open:
The change still applies cleanly to today's main, and every touched file is within 600 lines.
|
The qwen3_5 CUDA EXL3 admission and weights loader hard-coded the mul1
codebook: cuda_exl3_admit.zig looked only for .mul1 marker tensors and
checked only mul1 kernel variants, and cuda_exl3_weights.zig set
.codebook = .mul1 on every Weight and Layer literal.
The CUDA kernel variants table (zig/src/cuda/exl3.zig::variants) already
enumerates mcg at every supported width (halves 2..16), so the kernels
can decode mcg-codebook checkpoints on any supported bpw. The GLM CUDA
family (families/glm/cuda_exl3.zig) already loads mcg checkpoints the
same way through its own admit path.
This change teaches the Qwen3.5 CUDA loader to accept either codebook:
cuda_exl3_admit.zig
* add mcg_magic = 0xCBAC1FED alongside mul1_magic
* Group now carries .codebook: cuda.exl3.Codebook
* group() detects .mul1 first (keeps mul1 the common case),
then .mcg, else refuses with UnsupportedQwenQuantization
* denseGroup() uses g.codebook for variant lookup
cuda_exl3_weights.zig
* dense() sets .codebook = gr.codebook
* experts() captures the first expert's codebook, asserts every
expert of the same layer uses the same codebook, and the Layer
literal carries that codebook
cuda_exl3_loader_test.zig
* new test: an mcg-codebook group admits with codebook .mcg
* new test: an mcg marker with the wrong magic is refused
test-qwen35-exl3-admission-host: 5/5 pass, no error logs.
test-exl3-cuda-host: 671/681 pass, 10 skip (unchanged from baseline).
ff439ed to
5e2d4a1
Compare
|
Thank you @Ch0mpaa. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes. |
qwen3_5 cuda: accept mcg codebook alongside mul1
Scope of this PR, after review-driven split:
ee6a7f158.stage6c-cuda-dtypeat53f119bb1.What's in
ee6a7f158Accept turboderp's
Qwen3.5-2B-exl3mcg checkpoints alongside the mul1 marker at the admission layer (cuda_exl3_admit.zig). Dry-run refusals preserve the existing "unsupported quantization" error for unknown magics. No kernel changes.Admission tests added in
cuda_exl3_loader_test.zig:.mcg, halves16.What's NOT in this PR (moved out per Synthena review)
The f16 embed / f32 norm / f32 A_log widening work. Reason: it's a dtype-compatibility change, not an admission change, and it needs its own numerical tests (per review). It will ship in a separate PR with the F16/BF16 mapped-vs-device corruption fixed and bounded-error regression tests.
CI
CI on this fork's PR requires maintainer approval to run (
action_requiredon all workflows). Pre-split admission tests were green at the earlier tip; the force-push is a pure revert of the dtype commit, no new mcg code.